import 'package:dmz/base/pageWidget/base_stateful_widget.dart';
import 'package:dmz/base/widget/defult_widget.dart';
import 'package:dmz/business/mine/controller/garage_main_controller.dart';
import 'package:dmz/business/mine/model/share_model.dart';
import 'package:dmz/business/mine/widget/garage_widgets.dart';
import 'package:dmz/utils/sp_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

class ShareWidget extends StatelessWidget {
  const ShareWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<GarageController>(
        id: 'share',
        builder: (controller) {
          return controller.shareOutModels.isEmpty
              ? GarageWidgets.emptyWidget()
              : ListView.builder(
                  itemCount: controller.shareOutModels.length,
                  itemBuilder: (context, index) {
                    return lsitItem(controller.shareOutModels[index]);
                  });
        });
  }

  lsitItem(ShareOutModel data) {
    return Container(
            color: const Color(0xFF434650),
            child: Row(children: [
              motoImage(112.sp, data.photo ?? ''),
              Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                DefaultText(data.name ?? '', 48.sp,
                    textColor: const Color(0xFFF9F9F9),
                    fontWeight: FontWeight.w700),
                DefaultText(
                    SPUtils.timeIntToTimeStr(data.created_at ?? 0,
                        attern: 'yyyy-MM-dd HH:mm'),
                    28.sp,
                    textColor: const Color(0xFF999999))
              ]),
              const Expanded(child: SizedBox()),
              Row(children: [
                DefaultText('${data.count}${'人'.tr}', 32.sp,
                        textColor: const Color(0xFF23C565))
                    .marginOnly(right: 20.sp),
                Image.asset('assets/images/home/set/right_icon.png',
                    width: 18.sp, height: 32.sp)
              ]).marginOnly(right: 30.sp)
            ]))
        .didClipRRectAll(56.sp)
        .marginOnly(left: 32.sp, right: 32.sp, bottom: 20.sp);
  }

  motoImage(double width, String url) {
    return Container(
            color: const Color(0xFFA1A2A7),
            child: DefaultNetWorkImage(url, width: width, height: width))
        .didClipRRectAll(width)
        .marginOnly(top: 40.sp, bottom: 40.sp, right: 32.sp, left: 30.sp);
  }
}
